package com.qf.servlet;

import com.qf.Utils.DaoUtils;
import com.qf.entity.StudentClass;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(urlPatterns = "/studentClassManager")
public class StudentClassManagerServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<StudentClass> studentClasses = DaoUtils.getStudentClasses();

        addNo(studentClasses,req);
        resp.sendRedirect("queryStudentClass");


    }

    //添加班级和学号   2017 studentClass
    private void addNo(List<StudentClass> studentClasses,HttpServletRequest req) {
        for (StudentClass studentClass : new ArrayList<StudentClass>(studentClasses)) {
            String nameClass =req.getParameter(studentClass.getStudent().getName());
            if (!nameClass.equals("")) {
                studentClass.setStudentClass(nameClass);
            }
        }

    }
}
